package com.gdlgxy.oa.controller;


import com.gdlgxy.oa.bean.StudentList;
import com.gdlgxy.oa.service.StudentServer;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;

public class StudentDelCtrl extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 根据传入的编号删除学生
        // 获取学生编号
        int sno = Integer.parseInt(request.getParameter("Sno"));

        // 获取链表
        StudentList list = StudentServer.list();
        // 删除节点
        list.studentDel(sno);
        // 向数据库传递删除后链表
        // 删除成功就转发回学生链表
        if (StudentServer.del(list)) {
            request.getRequestDispatcher("/student/list").forward(request, response);
        } else {
            // 删除失败
            request.getRequestDispatcher("/error.html").forward(request, response);
        }
    }
}
